//----BEGIN LICENSE----//
/*****************************************************************\
** prevalentLite - sqlite3 persistence object library 
**
** Copyright (C) 2008 Philip R. Schuchardt
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program.  If not, see <http://www.gnu.org/licenses/>.
**
*****************************************************************/
//----END LICENSE----//

/*!
  \class plBool plBool.h <plBool>
  \brief plBool is a database aware integer.

  plBool can be used and should be used in the same way as a normal integer.  Make sure plBool::Setup() is called before using the class.  Without calling plBool::Setup(), the database doesn't know how to get or commit data.

  For example:
  \code

  plBool test;
  test.Setup("test", this);
  test = true;
  if(test) {
    test = false;
  }
  test = 1;

  bool temp = true;
  test = temp;

   \endcode

  */

//Our includes
#include "plBool.h"
#include "plObject.h"
#include "plDatabase.h"

//////////////////////////////////////////////// Public ////////////////////////////////////////////////////

//Constructor
plBool::plBool() : plData() {
	Cached = false;
}

//Constructor
plBool::plBool(double value) : plData () {
	Value = value;
	Disabled = true;
}

//Copy constructor
plBool::plBool(const plBool& obj) : plData(obj) {
	Copy(obj);
}

//Accessor
double plBool::Data() {
        plData::GetData();
	return Value;
}

//Modifier
void plBool::SetData(bool value) {
	Value = value;
        plData::SetData();
}

	
//Operator overloading
void plBool::operator=(bool value) {
	SetData(value);
	//return *this;
}

//Operator overloading
void plBool::operator=(const plBool& obj) {
	Copy(obj);
}

plBool::operator bool() {
	return Data();
}

//Does a smart copy of the object
void plBool::Copy(const plBool& obj) {
	SetData(obj.Value);
}
	

//Binds the data with the statement
void plBool::Bind(sqlite3_stmt* statement, int index) const {
	sqlite3_bind_int(statement, index, (int)Value);
}

	
//Gets the data from the current statement
void plBool::Column(sqlite3_stmt* statement, int index ) {
	Value = (bool)sqlite3_column_int(statement, index);
}


